let nums = [3, 2, 1]
var thirdMax = function (nums) {
    if (nums.length < 3) {
        return nums.sort((a, b) => b - a)[0]
    }
    const arr = nums.sort((a, b) => b - a)
    let map = new Map()
    let p = 0
    for (let i = 0; p < 3 && i < arr.length; i++) {
        if (!map.has(arr[i])) {
            p++
            map.set(arr[i], p)
        }
    }
    if (p === 3) {
        for (const key in map) {
            console.log(key);
            if (map.get(key) === 3) {
                return key
            }
        }
    }
    return arr[0]
};
console.log(thirdMax(nums));
